import Vue from 'vue'
import VueRouter from 'vue-router'
// 使用了路由懒加载就不需要再导入了
// import login from '@/views/login/index.vue'

Vue.use(VueRouter)

const routes = [
  // {
  //   path: '/',
  //   redirect: '/login'
  // },
  {
    path: '/login',
    // 路由懒加载
    // import是webpack内置的函数
    component: () => import('@/views/login/index.vue')
  },
  {
    //  
    path: '/',
    component: () => import('@/views/layout/index.vue'),
    redirect: '/my',
    children: [
      {
        path: 'home',
        component: () => import('@/views/home/index.vue')
      },
      {
        path: 'qa',
        component: () => import('@/views/qa/index.vue')
      },
      {
        path: 'my',
        component: () => import('@/views/my/index.vue')
      },
    ]
  },
  // 文章详情路由
  {
    // 需要携带文章项的id 作为路径参数
    path: '/article/:id',
    component: () => import('@/views/article'),
    // 为路由开启了props传参 
    // 假设访问/article/100 这个路径时
    // 就给文章详情页的组件传递一个自定义属性 id=100
    props: true
  }
]

const router = new VueRouter({
  routes
})

export default router
